class FriendLink < ActiveRecord::Base
  validates_presence_of :name, :url, :message => "请填写完整！"
  email_name_regex  = '[A-Z0-9_\.%\+\-]+'
  domain_head_regex = '(?:[A-Z0-9\-]+\.)+'
  domain_tld_regex  = '(?:[A-Z]{2,4}|museum|travel)'
  validates_format_of :email,
    :with => /^#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}$/i,
    :message => "Email格式不正确",
    :unless => Proc.new { |friend_link| friend_link.email.blank? }
  validates_format_of :url,
    :with => /^https?:\/\/([A-Z0-9]{1,}\.)?([A-Z0-9]{1,})(\.[A-Z]{2,4}){1,2}$/i,
    :message => "网站地址格式不正确"
  named_scope :passed_firend_links, :conditions => {:flag => 'pass'}
end
